package mortal.game.control
{
    import Framework.MQ.*;
    import Message.Command.*;
    import Message.Game.*;
    import modules.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class VIPController extends Controller
    {
        private var _vipModule:VIPModule;

        public function VIPController()
        {
            
        }

        override protected function initServer() : void
        {
            Dispatcher.addEventListener(EventName.StartVIPBless, this.onStartVIPBless);
            Dispatcher.addEventListener(EventName.StopVIPBless, this.onStopVIPBless);
            Dispatcher.addEventListener(EventName.ShowVIPWindow, this.onShowVIPWindow);
            Dispatcher.addEventListener(EventName.GetVIPRewards, this.onGetVIPRewards);
            Dispatcher.addEventListener(EventName.ShowVIPBoonWindow, this.onShowVIPBoonWindow);
            NetDispatcher.addCmdListener(ServerCommand.VIPInfoUpdateCommand, this.onVipInfoUpdate);
            NetDispatcher.addCmdListener(ServerCommand.VIPBlessStateChange, this.onVipBlessStateUpdate);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateTestVIPCard, this.onTestVipCardRes);
            
        }

        override protected function initView() : IView
        {
            if (!this._vipModule)
            {
                this._vipModule = new VIPModule();
                this.updateVIPInfo();
                this.updatePlayerBase();
            }
            return this._vipModule;
        }

        private function onStartVIPBless(event:DataEvent) : void
        {
            GameProxy.vip.startVIPBless();
            
        }

        private function onStopVIPBless(event:DataEvent) : void
        {
            GameProxy.vip.stopVIPBless();
            
        }

        private function onShowVIPWindow(event:DataEvent) : void
        {
            view.show();
            
        }

        private function onShowVIPBoonWindow(event:DataEvent) : void
        {
            view.show();
            (view as VIPModule).changeToOtherVipBoon(int(event.data));
            
        }

        private function onGetVIPRewards(event:DataEvent) : void
        {
            GameProxy.vip.getVIPRewards(int(event.data));
            
        }

        private function updateVIPInfo() : void
        {
            (view as VIPModule).updateVIPInfo(cache.vip.vipInfo);
            
        }

        private function updatePlayerBase() : void
        {
            (view as VIPModule).updatePlayerBase(cache.role.entityInfo);
            
        }

        private function onVipInfoUpdate(param1:Object) : void
        {
            (view as VIPModule).updateVIPInfo(cache.vip.vipInfo);
            
        }

        private function onVipBlessStateUpdate(param1:Boolean) : void
        {
            (view as VIPModule).setVIPBlessState(param1);
            
        }

        private function onTestVipCardRes(param1:MessageBlock) : void
        {
            cache.vip.vipTestCard = param1.messageBase as STestVIPCard;
            Dispatcher.dispatchEvent(new DataEvent(EventName.TestVIPCardRes));
            
        }

    }
}
